package com.yt.generator.engine;


import com.yt.generator.engine.base.TemplateEngine;
import com.yt.generator.utils.ToolUtil;

import java.io.File;

/**
 * 通用的模板生成引擎
 *
 * @author fengshuonan
 * @date 2017-05-09 20:32
 */
public class SimpleTemplateEngine extends TemplateEngine {

    @Override
    protected void generateControllerClient() {
        String controllerPath = ToolUtil.format(super.getContextConfig().getProjectBasePath() + super.controllerClientConfig.getPathTemplate(),
                ToolUtil.firstLetterToUpper(super.getContextConfig().getBizEnName()));
        if (!new File(controllerPath).exists()) {
            generateFile(contextConfig.getTemplatePrefixPath() + "/ControllerClient.java.btl", controllerPath);
            System.out.println("生成控制器成功!");
        }
    }

    @Override
    protected void generateControllerCms() {
        String controllerPath = ToolUtil.format(super.getContextConfig().getProjectBasePath() + super.controllerCmsConfig.getPathTemplate(),
                ToolUtil.firstLetterToUpper(super.getContextConfig().getBizEnName()));

        if (!new File(controllerPath).exists()) {
            generateFile(contextConfig.getTemplatePrefixPath() + "/ControllerCms.java.btl", controllerPath);
            System.out.println("生成控制器成功!"+controllerPath + "------"+super.controllerCmsConfig.getPathTemplate());
        }
    }

    @Override
    protected void generateService() {
        String path = ToolUtil.format(super.contextConfig.getProjectBasePath() + super.serviceConfig.getPathTemplate(),
                ToolUtil.firstLetterToUpper(super.contextConfig.getBizEnName()));
        if (!new File(path).exists()) {
            generateFile(contextConfig.getTemplatePrefixPath() + "/Service.java.btl", path);
            System.out.println("生成service成功!");
        }
    }

    @Override
    protected void generateServiceImpl() {
        String implPath = ToolUtil.format(super.contextConfig.getProjectBasePath() + super.serviceImplConfig.getPathTemplate(),
                ToolUtil.firstLetterToUpper(super.contextConfig.getBizEnName()));
        if (!new File(implPath).exists()) {
            generateFile(contextConfig.getTemplatePrefixPath() + "/ServiceImpl.java.btl", implPath);
            System.out.println("生成serviceImpl成功!");
        }
    }

    @Override
    protected void generateMapper() {
        String path = ToolUtil.format(super.contextConfig.getProjectBasePath() + super.mapperConfig.getPathTemplate(),
                ToolUtil.firstLetterToUpper(super.contextConfig.getBizEnName()));
        if (!new File(path).exists()) {
            generateFile(contextConfig.getTemplatePrefixPath() + "/Mapper.java.btl", path);
            System.out.println("生成mapper成功!");
        }

        String xmlPath = ToolUtil.format(super.contextConfig.getProjectBasePath() + super.mapperConfig.getMapperXmlPathTemplate(),
                ToolUtil.firstLetterToUpper(super.contextConfig.getBizEnName()));
        System.out.println(xmlPath);
        if (!new File(xmlPath).exists()) {
            generateFile(contextConfig.getTemplatePrefixPath() + "/Mapper.xml.btl", xmlPath);
            System.out.println("生成mapperXml成功!");
        }
    }

    @Override
    protected void generateModels() {
        String pathDTO = ToolUtil.format(super.contextConfig.getProjectBasePath() + modelsConfig.getDtoPathTemplate(),
                ToolUtil.firstLetterToUpper(super.contextConfig.getBizEnName()));
        if (!new File(pathDTO).exists()) {
            generateFile(contextConfig.getTemplatePrefixPath() + "/DTO.java.btl", pathDTO);
            System.out.println("生成entityDTO成功!");
        }

        String pathSaveBO = ToolUtil.format(super.contextConfig.getProjectBasePath() + super.modelsConfig.getSaveBOPathTemplate(),
                ToolUtil.firstLetterToUpper(super.contextConfig.getBizEnName()));
        if (!new File(pathSaveBO).exists()) {
            generateFile(contextConfig.getTemplatePrefixPath() + "/SaveBO.java.btl", pathSaveBO);
            System.out.println("生成entitySaveBO成功!");
        }

        String pathBO = ToolUtil.format(super.contextConfig.getProjectBasePath() + super.modelsConfig.getBoPathTemplate(),
                ToolUtil.firstLetterToUpper(super.contextConfig.getBizEnName()));
        if (!new File(pathBO).exists()) {
            generateFile(contextConfig.getTemplatePrefixPath() + "/BO.java.btl", pathBO);
            System.out.println("生成entityBO成功!");
        }

        String pathVO = ToolUtil.format(super.contextConfig.getProjectBasePath() + super.modelsConfig.getVoPathTemplate(),
                ToolUtil.firstLetterToUpper(super.contextConfig.getBizEnName()));
        if (!new File(pathVO).exists()) {
            generateFile(contextConfig.getTemplatePrefixPath() + "/VO.java.btl", pathVO);
            System.out.println("生成entityVO成功!");
        }
    }

    @Override
    protected void generateSqls() {
        String path = ToolUtil.format(super.contextConfig.getProjectBasePath() + super.sqlConfig.getSqlPathTemplate(),
                ToolUtil.firstLetterToUpper(super.getContextConfig().getBizEnName()));
        if (!new File(path).exists()) {
            generateFile(super.getContextConfig().getTemplatePrefixPath() + "/menu_sql.sql.btl", path);
            System.out.println("生成sql成功!");
        }
    }

}
